<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String dept_name = request.getParameter("dept_name") == null ? "" : request.getParameter("dept_name");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
	String customer_id = request.getParameter("customer_id") == null ? "" : request.getParameter("customer_id");
	String customer = request.getParameter("customer") == null ? "" : request.getParameter("customer");
%>
<html>
	<head>
		<title>甲供还料</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValueTwo").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
			});
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageGDCustomerReturn?gd_id=<%=gd_id%>',
				rownumbers:true,
				fitColumns:true,
				idField:'id',
				nowrap:false,
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'还料类型',field:'type',width:100,align:'center',formatter:function(value){
						if(value == '0'){
							return "还客户库";
						}
						if(value == '1'){
							return "还工余库";
						}
					}},
					{title:'还料日期',field:'operation_date',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:150,align:'center'},
					//{title:'还料部门',field:'dept_name',width:100,align:'center'},
					{title:'还料人',field:'person',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:100,align:'center'},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editReturnMaterial('"+rowData.type+"','"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteReturnMaterial('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.type+"','"+rowData.id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editReturnMaterial('"+rowData.type+"','"+rowData.id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.type+"','"+rowData.id+"');\"/>";
						}
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:showReturnMaterial('"+rowData.type+"','"+rowData.id+"');\"/>";
	
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var return_id = row.id;
					var type = row.type;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					if(type == 0){
						 ddv.datagrid({
								title:'明细',
								url:'<%=contextPath %>/springMVC/gd/listGDCustomerReturnDetail?return_id='+return_id,
								loadMsg:'正在加载数据，请稍后......',
								fitColumns:true,
								rownumbers:true,
								columns:[[
						            {title:'借料日期',field:'operation_date',width:100,align:'center'},
						            {title:'借料摘要',field:'summary',width:200,align:'center'},
									{title:'被借仓库',field:'warehouse_name',width:150,align:'center'},
									{title:'产品编号',field:'code',width:90,align:'center'},
									{title:'产品名称',field:'name',width:120,align:'center'},
									{title:'规格/型号',field:'format_type',width:120,align:'center'},
									{title:'单位',field:'unit_name',width:50,align:'center'},
									{title:'还料数量',field:'return_num',width:70,align:'center'}
								]],
							 	onResize:function(){
							        $('#table').datagrid('fixDetailRowHeight',index);
							    },
							 	onLoadSuccess:function(){
							       setTimeout(function(){
							         $('#table').datagrid('fixDetailRowHeight',index);
							       },0);
							   }
							 });
					}
					else if(type == 1){
						 ddv.datagrid({
							 title:'明细',
								url:'<%=contextPath %>/springMVC/gd/listGDCustomerReturnDetail?return_id='+return_id,
								loadMsg:'正在加载数据，请稍后......',
								fitColumns:true,
								rownumbers:true,
								columns:[[
						            {title:'借料日期',field:'operation_date',width:100,align:'center'},
						            {title:'借料摘要',field:'summary',width:200,align:'center'},
									{title:'产品编号',field:'code',width:90,align:'center'},
									{title:'产品名称',field:'name',width:120,align:'center'},
									{title:'规格/型号',field:'format_type',width:150,align:'center'},
									{title:'单位',field:'unit_name',width:50,align:'center'},
									{title:'还料数量',field:'return_num',width:100,align:'center'},
									{title:'还钱',field:'return_money',width:50,align:'center'}
								]],
							 	onResize:function(){
							        $('#table').datagrid('fixDetailRowHeight',index);
							    },
							 	onLoadSuccess:function(){
							       setTimeout(function(){
							         $('#table').datagrid('fixDetailRowHeight',index);
							       },0);
							   }
							 });
					}
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function shenpi(obj,type,id){
			 var flowBusinessUrl = "";
			 var param = "";
			if(type == 0){
		      flowBusinessUrl='<%=contextPath %>/springViews/gd/addOrEditCustomerReturn.jsp?isShow=1&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>&return_id='+id;
		      param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_RETURN_CUSTOMER_SHENPI%>")+"&businessId="+id;
			}
			else if(type == 1){
		      flowBusinessUrl='<%=contextPath %>/springViews/gd/addOrEditSelfReturn.jsp?isShow=1&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>&return_id='+id;
		      param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_RETURN_SELF_SHENPI%>")+"&businessId="+id;
			}
		      $(obj).hide();
		      $.ajax({
							type:'POST',
							url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
							dataType:"JSON",
							data:param,
							success:function(rtJson){
								if (rtJson.rtState == '0'){
									openDialogResize(rtJson.rtData.url,1000,800);
								}else{
									warningInfo(rtJson.rtMsrg);
								}
								$(obj).show();
							}
						});
		}
		
		function returnMaterial(type){
			if(type==0){
				//还客户库
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditCustomerReturn.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>",1000, 800);
			}else if(type==1){
				openDialogResize('<%=contextPath %>/springViews/gd/addOrEditSelfReturn.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>',1000, 800);
			}
		}
		function editReturnMaterial(type,return_id){
			if(type==0){
				//还客户库
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditCustomerReturn.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>&return_id="+return_id,1000, 800);
			}else if(type==1){
				openDialogResize('<%=contextPath %>/springViews/gd/addOrEditSelfReturn.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&return_id='+return_id,1000, 800);
			}
		}
		function showReturnMaterial(type,return_id){
			if(type==0){
				//还客户库
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditCustomerReturn.jsp?isShow=1&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>&return_id="+return_id,1000, 800);
			}else if(type==1){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditSelfReturn.jsp?isShow=1&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>&return_id="+return_id,1000, 800);
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteReturnMaterial(return_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteCustomerReturn?return_id="+return_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValueTwo = $('#searchValueTwo').val();
			$('#table').datagrid('load',{
				searchValueTwo:searchValueTwo,
				start_time:start_time,
				end_time:end_time
				
			});
		}
	</script>
	<body>
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="returnMaterial(0);">还客户库</a>
			</div>
			<div align="right">
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" />
				内容摘要：<input id="searchValueTwo" name="searchValueTwo" style="width:150px" title="内容摘要"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
